/*
 * Copyright (C) 2019 Baidu, Inc. All Rights Reserved.
 */
package com.example.park_management.utils;


import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


@Slf4j
public class DateUtils_lh {


    public static Date startOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        // 将Calendar对象的时分秒毫秒设置为0，即得到这一天的0点
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date startOfDay = calendar.getTime();

        return startOfDay;
    }


    public static Date endOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 将Calendar对象的时分秒毫秒设置为23:59:59.999，即得到这一天的23点
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        Date endOfDay = calendar.getTime();

        return endOfDay;
    }


    public static String format(Date time, String format) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(time);


    }

    public static long get13Time() {
        Calendar calendar = Calendar.getInstance();

        // 设置时间为今天的10点
        calendar.set(Calendar.HOUR_OF_DAY, 13);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 获取时间戳
        return calendar.getTimeInMillis();
    }

    public static long get10Time() {
        Calendar calendar = Calendar.getInstance();

        // 设置时间为今天的10点
        calendar.set(Calendar.HOUR_OF_DAY, 10);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 获取时间戳
        return calendar.getTimeInMillis();
    }

    public static long get19Time() {
        Calendar calendar = Calendar.getInstance();

        // 设置时间为今天的10点
        calendar.set(Calendar.HOUR_OF_DAY, 19);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 获取时间戳
        return calendar.getTimeInMillis();
    }



    public static long get22Time() {
        Calendar calendar = Calendar.getInstance();

        // 设置时间为今天的10点
        calendar.set(Calendar.HOUR_OF_DAY, 22);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 获取时间戳
        return calendar.getTimeInMillis();
    }


    public static Date getBforeTimeByDay(int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());  // 获取当前日期时间
        calendar.add(Calendar.DAY_OF_MONTH, -day);  // 将日期减去30天

        return calendar.getTime();


    }

    public static Date getTodayEndTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());  // 获取当前日期时间
        calendar.set(Calendar.HOUR_OF_DAY, 23);  // 设置小时为23
        calendar.set(Calendar.MINUTE, 59);      // 设置分钟为59
        calendar.set(Calendar.SECOND, 59);      // 设置秒数为59
        calendar.set(Calendar.MILLISECOND, 999); // 设置毫秒为999 (可选)

        return calendar.getTime();

    }


    public static Date getTodayStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());  // 获取当前日期时间
        calendar.set(Calendar.HOUR_OF_DAY, 0);  // 设置小时为0
        calendar.set(Calendar.MINUTE, 0);      // 设置分钟为0
        calendar.set(Calendar.SECOND, 0);      // 设置秒数为0
        calendar.set(Calendar.MILLISECOND, 0); // 设置毫秒为0

        return calendar.getTime();

    }

}
